﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.Diagnostics;

namespace AsyncWebStudyConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("执行1000条请求");
            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine("第" + i + "次模拟");

                {
                    Stopwatch watch = new Stopwatch();
                    HttpClient client = new HttpClient();

                    watch.Start();

                    Task[] tasks = new Task[1000];
                    for (var j = 0; j < 1000; j++)
                    {
                        tasks[j] = client.GetStringAsync("http://localhost:8768/AsyncHome/");
                    }
                    Task.WaitAll(tasks);
                    watch.Stop();

                    Console.WriteLine(watch.Elapsed);
                }

                {
                    Stopwatch watch = new Stopwatch();
                    HttpClient client = new HttpClient();

                    watch.Start();

                    Task[] tasks = new Task[1000];
                    for (var j = 0; j < 1000; j++)
                    {
                        tasks[j] = client.GetStringAsync("http://localhost:8768/Home/");
                    }
                    Task.WaitAll(tasks);
                    watch.Stop();

                    Console.WriteLine(watch.Elapsed);
                }
            }
        }
    }
}
